Skip to content

Add experimental RBAC model preset and optional helpers#1687

Open
Copilot wants to merge 4 commits intomasterfrom
copilot/add-rbac-model-preset
Open

Add experimental RBAC model preset and optional helpers#1687
Copilot wants to merge 4 commits intomasterfrom
copilot/add-rbac-model-preset

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Provides a programmatic RBAC model preset to eliminate boilerplate model.conf files for the common case.

Changes

Preset model (preset/preset.go)

  • RBAC() returns a standard RBAC model equivalent to examples/rbac_model.conf
  • Model text extracted as package constant for maintainability

Optional helpers (preset/rbac/rbac.go)

  • AssignRole(e, user, role) wraps AddRoleForUser
  • Grant(e, subject, object, action) wraps AddPolicy

Usage

m := preset.RBAC()
e, _ := casbin.NewEnforcer(m, adapter)

rbac.AssignRole(e, "alice", "admin")
rbac.Grant(e, "admin", "data1", "read")

ok, _ := e.Enforce("alice", "data1", "read") // true

Design

  • No new enforcement semantics—uses existing model.NewModelFromString()
  • Helpers are thin wrappers over existing enforcer methods
  • All existing APIs unchanged
Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] Add experimental RBAC model preset (and optional helpers)</issue_title>
<issue_description>## Background

Casbin models are currently defined by users via model.conf, which provides maximum flexibility but also requires users to repeatedly define common authorization patterns.

One of the most common patterns is standard RBAC (role-based access control) using p and g policies.

Proposal

Introduce an opinionated RBAC model preset that provides a reference implementation of standard RBAC.

Example usage:

m := preset.RBAC()
e, _ := casbin.NewEnforcer(m, adapter)

// optional helper
rbac.AssignRole(e, "alice", "admin")
rbac.Grant(e, "admin", "data1", "read")

ok, _ := e.Enforce("alice", "data1", "read")

Optionally, small helper functions may be provided to simplify common RBAC operations, such as assigning roles or granting permissions. These helpers operate on an existing Enforcer and do not introduce new abstractions or enforcement paths.

Design Notes

  • The preset generates a standard Casbin model equivalent to a typical model.conf
  • No new enforcement semantics are introduced
  • Existing APIs and behavior remain unchanged
  • Helpers (if included) are convenience-only and optional

Scope

In scope

  • A single, standard RBAC model preset
  • Optional helper functions for common RBAC operations

Out of scope

  • RBAC variants (e.g. domains)
  • ABAC or other authorization patterns</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
@hsluoyz hsluoyz marked this pull request as ready for review January 20, 2026 03:21
Copilot AI and others added 2 commits January 20, 2026 03:22
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
…ove error handling

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add experimental RBAC model preset and helpers Add experimental RBAC model preset and optional helpers Jan 20, 2026
Copilot AI requested a review from hsluoyz January 20, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Add experimental RBAC model preset (and optional helpers)

3 participants